﻿using System;
using System.Data;
using System.Collections.Generic;
using eTMS.Controllers.DangKyHocPhanService;
namespace eTMS.Controllers{
public class DangKyHocPhanControllerBase : CommonController{
	public DangKyHocPhanControllerBase()
		: base()
	{	
		this.dao = new DangKyHocPhanServiceClient();
	}
	~DangKyHocPhanControllerBase(){
		if(dao.State==System.ServiceModel.CommunicationState.Opened)try{dao.Close();}catch{}
	}
	private DataTable _Table;
	private DangKyHocPhanEntity oDangKyHocPhan;	
	public DangKyHocPhanEntity DangKyHocPhanObject{
		get{
			return oDangKyHocPhan;
		}
		set{
			oDangKyHocPhan=value;
		}
	}
	protected DangKyHocPhanServiceClient dao;
	public DataTable Table{
		get{			
			return _Table;
		}
        set
        {
            _Table = value;
        }
	}	
	public void AddIndexToTable(){
		this.AddIndexToTable(_Table);
	}
	public void ResetTableIndex(){
		this.ResetTableIndex(_Table);
	}
	public bool AddNew(){
		if(oDangKyHocPhan==null)return false;
		bool result=true;
		try{
			oDangKyHocPhan = dao.SaveRet(oDangKyHocPhan);
		}
		catch{
			result=false;
		}
		return result;
	}
	public bool Update(){
		if(oDangKyHocPhan==null)return false;
		return dao.Update(oDangKyHocPhan);
	}
	public bool Delete(){
		if(oDangKyHocPhan==null)return false;
		bool retvalue = dao.Delete(oDangKyHocPhan);
		return retvalue;
	}
	public bool DeleteByID(Int32 DangKyHocPhan_ID){
		bool retvalue = dao.DeleteByID(DangKyHocPhan_ID);		
		return retvalue;
	}
	public void ResetObject(){
		this.oDangKyHocPhan = new DangKyHocPhanEntity();
	}
    //Copy data from data row in grid to object
    public DangKyHocPhanEntity MapDataRowToObject(DataRow row){
		DangKyHocPhanEntity o = new DangKyHocPhanEntity();
		 if(!row.IsNull("NgayDangKy"))
			o.NgayDangKy=ConvertDateTime(row["NgayDangKy"]);
		 if(!row.IsNull("HocKy_ID"))
			o.HocKy_ID=(Int32)(row["HocKy_ID"]);
		 if(!row.IsNull("MonHoc_ID"))
			o.MonHoc_ID=(Int32)(row["MonHoc_ID"]);
		 if(!row.IsNull("NamHoc_ID"))
			o.NamHoc_ID=(Int32)(row["NamHoc_ID"]);
		 if(!row.IsNull("SinhVien_ID"))
			o.SinhVien_ID=(Int32)(row["SinhVien_ID"]);
		 if(!row.IsNull("DangKyHocPhan_ID"))
		    o.DangKyHocPhan_ID=(Int32)(row["DangKyHocPhan_ID"]);
		 return o;
    }
	//Copy data from object to data row in grid    
    public void MapObjectToDataRow(DangKyHocPhanEntity o,DataRow row){
		row["NgayDangKy"]=o.NgayDangKy;
		row["HocKy_ID"]=o.HocKy_ID;
		row["MonHoc_ID"]=o.MonHoc_ID;
		row["NamHoc_ID"]=o.NamHoc_ID;
		row["SinhVien_ID"]=o.SinhVien_ID;
		row["DangKyHocPhan_ID"]=o.DangKyHocPhan_ID;
    }
    public void MapObjectToDataRow(DataRow row){
		this.MapObjectToDataRow(this.DangKyHocPhanObject,row);
    }
	public void LoadObject(Int32 DangKyHocPhan_ID){
			oDangKyHocPhan=dao.SelectOne(DangKyHocPhan_ID);
	}
}
}
